package com.nmgdz.bigdata.controller;

import com.nmgdz.bigdata.entity.User;

import com.nmgdz.bigdata.service.RedisService;
import com.nmgdz.bigdata.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("user")
public class UserController {
    @Autowired

    private UserService userService;

    @Autowired
    private RedisService redisService;

    @GetMapping("/gueryBuId")
    public String gueryById(int id) {
        String userStr = redisService.get(id + "");
        if (userStr==null) {
            redisService.set(id + "", userService.gueryById(id).toString());
        }
        return userStr;

    }
    @PatchMapping("/save")
    public User saveUser(String name,int age){
        return userService.save(new User(name,age));

    }


}
